package com.group.controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import com.base.view.BaseResult;
import com.base.view.GeneralResult;
import com.base.view.ListResult;
import com.group.model.Tag;

/**
 * 标签管理
 * @author zhaolei
 *
 */
@Controller
public class TagController extends BaseController {
	
	/**
	 * 添加/修改标签
	 * @param tag
	 * @return
	 */
	@PostMapping("/tag/add")
	@ResponseBody
	public GeneralResult<Tag> addTag(@RequestBody Tag tag){
		beanDao.save(tag);
		
		return new GeneralResult<Tag>().setValue(tag);
	}
	
	/**
	 * 删除标签
	 * @param tagId
	 * @return
	 */
	@DeleteMapping("/tag/delete")
	@ResponseBody
	public BaseResult deleteTag(Long tagId) {
		beanDao.quickDelete(Tag.class, "id", tagId);
		return new BaseResult();
	}
	
	/**
	 * 查询标签
	 * @param key 关键字
	 * @param start
	 * @param limit
	 * @return
	 */
	@GetMapping("/tag/query")
	@ResponseBody
	public ListResult<Tag> queryTag(String key ,Integer start,Integer limit){
		
		return new ListResult<Tag>().setList(newsDao.queryTag(key, start, limit)).setTotal(newsDao.queryTagCount(key));
	}

}
